﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using Ppt = Microsoft.Office.Interop.PowerPoint;

namespace ObjectModel.PowerPoint.New
{
    public class ConstantSourceOld : ObservableSourceObject<Constant>
    {
        //Constant mConstant;
        
        public ConstantSourceOld() // Parameterless constructor required for deserialization.
        { }

        public ConstantSourceOld(Constant constant)
        {
            base.Source = constant;
        }

        public string ConstantName // This property holds the serializable info.
        {
            get { return base.Source.Name; }
            set
            {
                try
                {
                    Ppt.Presentation pres = Globals.Application.ActivePresentation;
                    base.Source = Globals.PresentationConstants[pres].Constants.Single(c => c.Name == value);
                }
                catch (InvalidOperationException)
                {
                    throw new InvalidOperationException(string.Format("Constant \"{0}\" no longer exists.", value));
                }
            }
        }

        //[XmlIgnore]
        //public Constant Constant // This property holds the live source object reference.
        //{
        //    get { return mConstant; }
            
        //    set
        //    {
        //        mConstant = value;
        //        mConstant.PropertyChanged += Constant_PropertyChanged;
        //    }
        //}

        //void Constant_PropertyChanged(object sender, PropertyChangedEventArgs e)
        //{
        //    if (e.PropertyName == Constant.ValuePropertyName)
        //        OnValueChanged();
        //}

        public override string GetValue()
        {
            return base.Source.Value;
        }

        //public override void UnhookEvents()
        //{
        //    mConstant.PropertyChanged -= Constant_PropertyChanged;
        //}
    }
}
